package com.zsjt.app.config.mvc;

import com.zsjt.app.compoent.localResolver.AppLocalResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * mvc配置类
 * 使用WebMvcConfigurer可以来扩展SpringMVC的功能
 * @author zhanb
 * @EnableWebMvc 全面接管mvc,所有springmvc自动配置失效
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    //所有的WebMvcConfigurer组件会一起起作用
    @Bean//将组件注入容器中
    public WebMvcConfigurer webMvcConfigurer(){
        WebMvcConfigurer webMvcConfigurer = new WebMvcConfigurer() {
            //视图映射
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("login");
                registry.addViewController("/login").setViewName("login");
                //registry.addViewController("/main.html").setViewName("index/main");
            }
            //资源映射
            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry){
                registry.addResourceHandler("/images/**").addResourceLocations("file:E:/Springboot/app/src/main/resources/static/asserts/images/avatar/");
            }
            //注册拦截器
          /*  @Override
            public void addInterceptors(InterceptorRegistry registry) {
                //springboot不需要处理静态资源
                registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                        .excludePathPatterns("/index.html" , "/" , "/admin/index","/user/login" , "/webjars/**" , "/asserts/**" , "/js/**" );
            }*/
        };
        return webMvcConfigurer;
    }

    /**
     * 国际化
     * @return
     */
    @Bean
    public AppLocalResolver localeResolver(){
        return  new AppLocalResolver();
    }

}
